package com.sdp.wx.db.wx_repair_vehicle_other_expense.service.impl;

import com.sdp.wx.db.wx_repair_vehicle_other_expense.entity.WxRepairVehicleOtherExpense;
import com.sdp.wx.db.wx_repair_vehicle_other_expense.mapper.WxRepairVehicleOtherExpenseMapper;
import com.sdp.wx.db.wx_repair_vehicle_other_expense.service.IWxRepairVehicleOtherExpenseService;
import com.sdp.wx.utils.WxConstants;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zsp
 * @since 2024-02-20
 */
@Service
public class WxRepairVehicleOtherExpenseServiceImpl extends ServiceImpl<WxRepairVehicleOtherExpenseMapper, WxRepairVehicleOtherExpense> implements IWxRepairVehicleOtherExpenseService {

	@Override
	public BigDecimal queryExtraAmount(String repairCode) {
		LambdaQueryWrapper<WxRepairVehicleOtherExpense> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(WxRepairVehicleOtherExpense::getRepairCode, repairCode);
		List<WxRepairVehicleOtherExpense> list = list(queryWrapper);
		if(list==null || list.size()==0) {
			return BigDecimal.ZERO;
		}
		
		BigDecimal extraAmount = BigDecimal.ZERO;
		for(WxRepairVehicleOtherExpense oe : list) {
			extraAmount = extraAmount.add(oe.getExpenseAmount());
		}
		
		return extraAmount;
	}

	@Override
	public BigDecimal queryArmyExtraAmount(String repairCode) {
		LambdaQueryWrapper<WxRepairVehicleOtherExpense> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(WxRepairVehicleOtherExpense::getRepairCode, repairCode);
		queryWrapper.eq(WxRepairVehicleOtherExpense::getIsArmyExpense, WxConstants.是.getCode());
		List<WxRepairVehicleOtherExpense> list = list(queryWrapper);
		if(list==null || list.size()==0) {
			return BigDecimal.ZERO;
		}
		
		BigDecimal extraAmount = BigDecimal.ZERO;
		for(WxRepairVehicleOtherExpense oe : list) {
			extraAmount = extraAmount.add(oe.getExpenseAmount());
		}
		
		return extraAmount;
	}

	@Override
	public List<WxRepairVehicleOtherExpense> queryRepairVehicleOtherExpenseByRepairCode(String repairCode,
			String isArmy) {
		LambdaQueryWrapper<WxRepairVehicleOtherExpense> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(WxRepairVehicleOtherExpense::getRepairCode, repairCode);
		queryWrapper.eq(WxRepairVehicleOtherExpense::getIsArmyExpense, isArmy);
		return list(queryWrapper);
	}

}
